﻿using System;

using log4net;

namespace StreakyDownloader.Model
{
   /// <summary>
   /// Encapsulates the loading and error handling associated with getting
   /// the necessary values from the application config file.
   /// </summary>
   public class StreakyDownloadConfig
   {
      ILog logger = LogManager.GetLogger(typeof(StreakyDownloadConfig));

      /// <summary>
      /// Documentation for each member exists in the actual configuration file.
      /// to keep down on duplication, see the app.config file for explanation.
      /// </summary>
      protected string baseUIFile;
      protected string baseDLFile;
      protected string download_ID_DataFile;
      protected bool open_UI_Page;
     
      #region Properties
      public string BaseUIFile
      {
         get { return baseUIFile; }
      }

      public string BaseDLFile
      {
         get { return baseDLFile; }
      }

      public string DownloadIDDataFile
      {
         get { return download_ID_DataFile; }
      }

      public bool OpenUIPage
      {
         get { return open_UI_Page; }
      }

      #endregion

      public StreakyDownloadConfig()
      {
         LoadConfigValues();
      }

      protected void LoadConfigValues()
      {
         try
         {
            baseUIFile = System.Configuration.ConfigurationSettings.AppSettings["baseUIFile"];
         }
         catch (Exception ex)
         {
            logger.Error("Error loading the baseUIFile setting from configuration file.", ex);
         }

         try
         {
            baseDLFile = System.Configuration.ConfigurationSettings.AppSettings["baseDLFile"];
         }
         catch (Exception ex)
         {
            logger.Error("Error loading the baseDLFile setting from configuration file.", ex);
         }

         try
         {
            download_ID_DataFile = System.Configuration.ConfigurationSettings.AppSettings["download_ID_DataFile"];
         }
         catch (Exception ex)
         {
            logger.Error("Error loading the download_ID_DataFile setting from configuration file.", ex);
         }

         try
         {
            open_UI_Page = Convert.ToBoolean(System.Configuration.ConfigurationSettings.AppSettings["open_UI_Page"]);
         }
         catch (Exception ex)
         {
            logger.Error("Error loading the open_UI_Page setting from configuration file.", ex);
         }
      }
   }
}
